package com.example.heatbeat;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
/**
 * @author xingzhiwen
 * @date 2021/11/16
 * @ddescription:
 */
/**
 * 服务端启动类
 *
 * @author Administrator
 *
 */
public class NettyUDPServerTest {

    public void run(int port) throws Exception {
        EventLoopGroup group = new NioEventLoopGroup();//线程池
        try {
            Bootstrap b = new Bootstrap();
            b.group(group).channel(NioDatagramChannel.class).option(ChannelOption.SO_BROADCAST, true).handler(new NettyUDPServerHandler());
            b.bind(port).sync().channel().closeFuture().await();
        } finally {
            group.shutdownGracefully();
        }
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int port = 8080;
        try {
            new NettyUDPServerTest().run(port);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
